package ru.myrtle.umf.tools.ugen.templates;

import java.io.*;
import java.text.*;
import java.util.*;
import ru.myrtle.umf.*;
import ru.myrtle.umf.codegen.*;
import ru.myrtle.umf.codegen.java.*;
import ru.myrtle.umf.tools.ugen.*;

public class UEnumerationDelegateTemplate extends UTemplate
{
    protected final String NL = System.getProperties().getProperty("line.separator");
    protected final String TEXT_1 = "package ";
    protected final String TEXT_2 = ";" + NL + NL + "public interface ";
    protected final String TEXT_3 = " {" + NL + NL;
    protected final String TEXT_4 = "    ";
    protected final String TEXT_5 = ";" + NL;
    protected final String TEXT_6 = "}" + NL;

    /*
     *
     */


    public UEnumerationDelegateTemplate() {

    }

    /*
     *
     */

    public String generate(UTemplateContext context) throws UTemplateRejectException
    {
        final StringBuffer stringBuffer = new StringBuffer();

    checkTemplateObjectType(context, UEnumeration.class);

    UEnumeration object = (UEnumeration) context.getObject();

    if (object.getOperations().isEmpty()) {
        reject();
    }

    String enumDelegateClassName     = UGenUtil.getEnumerationDelegateClassName(object);
    String enumDelegateClassPackage  = UGenUtil.getEnumerationDelegateClassPackage(object);

    context.getResource().setObjectFileName(enumDelegateClassName);
    context.getResource().setObjectFileExtension("java");
    context.getResource().setObjectPackage(enumDelegateClassPackage);

    JavaImportBuilder importBuilder = new JavaImportBuilder();

    createDoc();
    addDocDescription(
            object.getDescription()
    );
    addDocAnnotation("generated");

        stringBuffer.append(TEXT_1);
        stringBuffer.append(enumDelegateClassPackage);
        stringBuffer.append(TEXT_2);
        stringBuffer.append(enumDelegateClassName);
        stringBuffer.append(TEXT_3);

    for (UOperation operation : object.getOperations()) {
        String signature = UGenUtil.createOperationSignature(
                operation, importBuilder, false, false, "", "public"
        );

        stringBuffer.append(TEXT_4);
        stringBuffer.append(signature);
        stringBuffer.append(TEXT_5);

    }

        stringBuffer.append(TEXT_6);

    insertImport(stringBuffer, importBuilder, enumDelegateClassPackage);


        return stringBuffer.toString();
    }

    // ---------------------------------------------------------------------------------------
    // ---------------------------------------------------------------------------------------

}
